//
//  AVObject+AVObject_Category.m
//  FunnyVideo
//
//  Created by 李鑫 on 15/10/23.
//  Copyright © 2015年 NewEggTech. All rights reserved.
//

#import "AVObject+AVObject_Category.h"

@implementation AVObject (AVObject_Category)


- (NSString *)stringValueForKey:(NSString *)key{
    id str = [self objectForKey:key];
    
    if(!str)
        return @"无";
        
    if([[str class] isSubclassOfClass:[NSString class]])
        return str;
    else
        return [str stringValue];
}

- (NSNumber *)numberValueForKey:(NSString *)key{
    id num = [self objectForKey:key];
    
    if([[num class] isSubclassOfClass:[NSNumber class]])
        return num;
    else
    {
        int int_num = [num intValue];
        
        return [NSNumber numberWithInt:int_num];
    }
}

- (NSDate *)dateValueForKey:(NSString *)key{
    id date = [self objectForKey:key];
    
    if([[date class] isSubclassOfClass:[NSDate class]])
        return date;
    else
    {
        if([[date class] isSubclassOfClass:[NSString class]])
        {
            NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]
            init];
            
            [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
            
            NSDate *convDate = [dateFormatter dateFromString:date];
            
            return convDate;
        }
        
        return [NSDate date];
    }
}

- (void)relationValueForClass:(NSString *)parentClass key:(NSString *)keyName syncCompletion:(void (^)(BOOL, NSArray *))completion{
    
    AVQuery *relationQuery = [AVRelation reverseQuery:parentClass relationKey:keyName childObject:self];
    
    [relationQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        
    }];
}

- (BOOL)boolValueForKey:(NSString *)key{
    return [[self objectForKey:key] boolValue];
}



+ (Class)classForVideoInfoType:(AVOSVideoInfoType)videoInfoType
{
    switch (videoInfoType) {
        case AVOSVideoInfoTypeContent:
            return [NSString class];
            break;
        case AVOSVideoInfoTypeVideoName:
            return [NSString class];
            break;
        case AVOSVideoInfoTypeVideoURL:
            return [NSString class];
            break;
        case AVOSVideoInfoTypePubUser:
            return [NSString class];
            break;
        case AVOSVideoInfoTypeCategory:
            return [NSString class];
            break;
            
        case AVOSVideoInfoTypeVideoId:
            return [NSString class];
            break;
        case AVOSVideoInfoTypeComments:
            return [NSString class];
            break;
        case AVOSVideoInfoTypeLikes:
            return [NSString class];
            break;
        case AVOSVideoInfoTypeIndex:
            return [NSNumber class];
            break;
        case AVOSVideoInfoTypeCreatedAt:
            return [NSDate class];
            break;
        default:
            return [NSString class];
            break;
    }
}

- (NSString *)stringWithAVOSVideoInfoType:(AVOSVideoInfoType)type
{
    switch (type) {
        case AVOSVideoInfoTypeContent:
            return @"content";
            break;
        case AVOSVideoInfoTypeVideoName:
            return @"videoName";
            break;
        case AVOSVideoInfoTypeVideoURL:
            return @"videoUrl";
            break;
        case AVOSVideoInfoTypePubUser:
            return @"pubUser";
            break;
        case AVOSVideoInfoTypeCategory:
            return @"Category";
            break;
            
        case AVOSVideoInfoTypeVideoId:
            return @"objectId";
            break;
        case AVOSVideoInfoTypeComments:
            return @"comments";
            break;
        case AVOSVideoInfoTypeLikes:
            return @"likes";
            break;
        case AVOSVideoInfoTypeIndex:
            return @"index";
            break;
        case AVOSVideoInfoTypeCreatedAt:
            return @"createdAt";
            break;
        default:
            return @"videoName";
            break;
    }
}

@end
